package com.zj.fx.controller.month;

import com.github.pagehelper.PageInfo;
import com.zj.fx.common.base.BaseController;
import com.zj.fx.common.domain.AjaxResult;
import com.zj.fx.common.domain.ResultTable;
import com.zj.fx.model.custom.InfoProjectVo;
import com.zj.fx.model.custom.Tablepar;
import com.zj.fx.model.info.InfoFile;
import com.zj.fx.model.info.InfoFileExample;
import com.zj.fx.model.info.InfoTargetStep;
import com.zj.fx.model.info.InfoTargetStepExample;
import com.zj.fx.model.month.MonthConstant;
import com.zj.fx.model.month.MonthSupplytaskDtl;
import com.zj.fx.model.month.MonthSupplytaskDtlExample;
import com.zj.fx.service.info.InfoFileService;
import com.zj.fx.service.info.InfoProjectService;
import com.zj.fx.service.info.InfoTargetStepService;
import com.zj.fx.service.month.MonthSupplytaskDtlService;
import com.zj.fx.shiro.util.ShiroUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.logging.log4j.util.Strings;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

/**
 * 月度供电所填报任务填报明细Controller
 *
 * @author SQL
 * @ClassName: MonthSupplytaskDtlController
 * @date 2023-06-09 17:15:40
 */
@Api(value = "月度供电所填报任务填报明细")
@Controller
@RequestMapping("/MonthSupplytaskDtlController")
public class MonthSupplytaskDtlController extends BaseController {

    private String prefix = "month/monthSupplytaskDtl";
    private String prefix1 = "month/monthSupplytask";

    @Autowired
    private MonthSupplytaskDtlService monthSupplytaskDtlService;

    @Autowired
    private InfoProjectService infoProjectService;

    @Autowired
    private InfoTargetStepService infoTargetStepService;

    @Autowired
    private InfoFileService infoFileService;

    /**
     * 月度供电所填报任务填报明细页面展示
     *
     * @param model
     * @return String
     * @author SQL
     */
    @ApiOperation(value = "分页跳转", notes = "分页跳转")
    @GetMapping("/view")
    @RequiresPermissions("gen:monthSupplytaskDtl:view")
    public String view(ModelMap model) {
        return prefix + "/list";
    }

    /**
     * list集合
     *
     * @param tablepar
     * @param
     * @return
     */
    //@Log(title = "月度供电所填报任务填报明细", action = "111")
    @ApiOperation(value = "分页跳转", notes = "分页跳转")
    @GetMapping("/list")
    @RequiresPermissions("gen:monthSupplytaskDtl:list")
    @ResponseBody
    public ResultTable list(Tablepar tablepar, MonthSupplytaskDtl monthSupplytaskDtl) {
        PageInfo<MonthSupplytaskDtl> page = monthSupplytaskDtlService.list(tablepar, monthSupplytaskDtl);
        return pageTable(page.getList(), page.getTotal());
    }

    /**
     * 新增跳转
     */
    @ApiOperation(value = "新增跳转", notes = "新增跳转")
    @GetMapping("/add")
    public String add(ModelMap modelMap) {
        return prefix + "/add";
    }

    /**
     * 新增保存
     *
     * @param
     * @return
     */
    //@Log(title = "月度供电所填报任务填报明细新增", action = "111")
    @ApiOperation(value = "新增", notes = "新增")
    @PostMapping("/add")
    @RequiresPermissions("gen:monthSupplytaskDtl:add")
    @ResponseBody
    public AjaxResult add(MonthSupplytaskDtl monthSupplytaskDtl) {
        int b = monthSupplytaskDtlService.insertSelective(monthSupplytaskDtl);
        if (b > 0) {
            return success();
        } else {
            return error();
        }
    }

    /**
     * 月度供电所填报任务填报明细删除
     *
     * @param ids
     * @return
     */
    //@Log(title = "月度供电所填报任务填报明细删除", action = "111")
    @ApiOperation(value = "删除", notes = "删除")
    @DeleteMapping("/remove")
    @RequiresPermissions("gen:monthSupplytaskDtl:remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        int b = monthSupplytaskDtlService.deleteByPrimaryKey(ids);
        if (b > 0) {
            return success();
        } else {
            return error();
        }
    }


    /**
     * 修改跳转
     *
     * @param id
     * @param
     * @return
     */
    @ApiOperation(value = "修改跳转", notes = "修改跳转")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap map) {
        map.put("MonthSupplytaskDtl", monthSupplytaskDtlService.selectByPrimaryKey(id));

        return prefix + "/edit";
    }

    /**
     * 修改保存
     */
    //@Log(title = "月度供电所填报任务填报明细修改", action = "111")
    @ApiOperation(value = "修改保存", notes = "修改保存")
    @RequiresPermissions("gen:monthSupplytaskDtl:edit")
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(MonthSupplytaskDtl monthSupplytaskDtl) {
        return toAjax(monthSupplytaskDtlService.updateByPrimaryKeySelective(monthSupplytaskDtl));
    }

    /**
     * 查询五级填报项目及其上级溯源
     *
     * @param
     * @param
     * @return
     */
    @ApiOperation(value = "查询五级填报项目及其上级", notes = "查询五级填报项目及其上级")
    @GetMapping("/list2/{taskId}/{tab}")
    @ResponseBody
    public Map<String, Object> list2(@PathVariable("taskId") String taskId, @PathVariable("tab") String tab, MonthSupplytaskDtl monthSupplytaskDtlVo) {
        Map<String, Object> map = new HashMap<>();
        List<MonthSupplytaskDtl> resultList = new ArrayList<>();

        InfoProjectVo infoProjectVo = new InfoProjectVo();
        infoProjectVo.setTab(tab);
        //查询三级固定项目
        List<InfoProjectVo> list = infoProjectService.findupGrade3(infoProjectVo);
        for (int i = 0; i < list.size(); i++) {
            MonthSupplytaskDtl monthSupplytaskDtlVo1 = new MonthSupplytaskDtl();
            monthSupplytaskDtlVo1.setId(list.get(i).getId());
            monthSupplytaskDtlVo1.setType(list.get(i).getType());
            monthSupplytaskDtlVo1.setContent(list.get(i).getContent());
            monthSupplytaskDtlVo1.setName(list.get(i).getName());
            monthSupplytaskDtlVo1.setScore(list.get(i).getScore());
            monthSupplytaskDtlVo1.setSelfValue(list.get(i).getSelfValue());

            MonthSupplytaskDtl monthSupplytaskDtlVo2 = new MonthSupplytaskDtl();
            monthSupplytaskDtlVo2.setFkTaskId(taskId);
            monthSupplytaskDtlVo2.setTab(tab);
            monthSupplytaskDtlVo2.setThreegradeNum(list.get(i).getId());
            List<MonthSupplytaskDtl> monthSupplytaskDtlVos = monthSupplytaskDtlService.list2(monthSupplytaskDtlVo2);

            //查询是否有辅助说明文档
            for (MonthSupplytaskDtl supplytaskDtl : monthSupplytaskDtlVos) {
                //临时增加，去除换行符，否则前端传递参数带换行符有问题，后期考虑前端优化
                String content = supplytaskDtl.getContent();
                Pattern p = Pattern.compile("\\s*|\t|\r|\n"); // 去除多个空格，去除制表符，回车，换行
                Matcher m = p.matcher(content);
                content = m.replaceAll("");
                supplytaskDtl.setContent(content);
                //查询是否有辅助说明文档
                InfoTargetStepExample infoTargetStepExample = new InfoTargetStepExample();
                infoTargetStepExample.createCriteria().andFkTargetIdEqualTo(supplytaskDtl.getNum());
                List<InfoTargetStep> infoTargetSteps = infoTargetStepService.selectByExample(infoTargetStepExample);
                if (infoTargetSteps!=null && infoTargetSteps.size()>0){
                    supplytaskDtl.setIshasStep(MonthConstant.IS);
                }else {
                    supplytaskDtl.setIshasStep(MonthConstant.NOT);
                }
                //查询是否有支撑文件及材料模板
                InfoFileExample infoFileExample = new InfoFileExample();
                List<String> subjectList = new ArrayList<>();
                subjectList.add("1");
                subjectList.add("2");
                infoFileExample.createCriteria().andFkRecordEqualTo(supplytaskDtl.getFkParentProjectId()).andFkSubjectIn(subjectList);
                List<InfoFile> infoFiles = infoFileService.selectByExample(infoFileExample);
                supplytaskDtl.setIshasSupport("0");
                supplytaskDtl.setIshasTemp("0");
                for (InfoFile infoFile : infoFiles) {
                    if ("1".equals(infoFile.getFkSubject())){
                        supplytaskDtl.setIshasSupport("1");
                    }else if ("2".equals(infoFile.getFkSubject())){
                        supplytaskDtl.setIshasTemp("1");
                    }
                }
                //查询是否有佐证文件
                InfoFileExample infoFileExample1 = new InfoFileExample();
                infoFileExample1.createCriteria().andFkRecordEqualTo(supplytaskDtl.getFkParentProjectId()).andFkTaskIdEqualTo(taskId);
                List<InfoFile> proofinfoFiles = infoFileService.selectByExample(infoFileExample1);
                supplytaskDtl.setIshasProof("0");
                if (proofinfoFiles!=null && proofinfoFiles.size()>0){
                    supplytaskDtl.setIshasProof("1");
                }
            }

            //查询三级项目对应模块下的自评价总分
            BigDecimal pro4Score = BigDecimal.ZERO;
            MonthSupplytaskDtlExample monthSupplytaskDtlExample = new MonthSupplytaskDtlExample();
            MonthSupplytaskDtlExample.Criteria criteria = monthSupplytaskDtlExample.createCriteria();
            criteria.andFkTaskIdEqualTo(taskId);
            criteria.andFkParentProjectIdEqualTo(list.get(i).getId());
            List<MonthSupplytaskDtl> monthSupplytaskDtls = monthSupplytaskDtlService.selectByExample(monthSupplytaskDtlExample);
            List<MonthSupplytaskDtl> collect = monthSupplytaskDtls.stream().filter(s -> Strings.isNotBlank(s.getSelfScore())).collect(Collectors.toList());
            if (collect.size() == monthSupplytaskDtls.size()) {
                pro4Score = monthSupplytaskDtls.stream().map(MonthSupplytaskDtl::getSelfScore).map(BigDecimal::new).reduce(BigDecimal.ZERO, BigDecimal::add);
            }

            monthSupplytaskDtlVo1.setProscore(pro4Score.toString());
            resultList.add(monthSupplytaskDtlVo1);
            resultList.addAll(monthSupplytaskDtlVos);
        }
        map.put("code", 0);
        map.put("msg", "");
        map.put("count", resultList.size());
        map.put("data", resultList);
        return map;
    }

    /**
     * 查询五级填报项目及其上级溯源
     *
     * @param
     * @param
     * @return
     */
    @ApiOperation(value = "查询五级填报项目及其上级", notes = "查询五级填报项目及其上级")
    @GetMapping("/list4subaudit/{taskId}/{tab}")
    @ResponseBody
    public Map<String, Object> list4subaudit(@PathVariable("taskId") String taskId, @PathVariable("tab") String tab, MonthSupplytaskDtl monthSupplytaskDtlVo) {
        Map<String, Object> map = new HashMap<>();
        List<MonthSupplytaskDtl> resultList = new ArrayList<>();

        InfoProjectVo infoProjectVo = new InfoProjectVo();
        infoProjectVo.setTab(tab);
        //查询三级固定项目
        List<InfoProjectVo> list = infoProjectService.findupGrade3(infoProjectVo);
        for (int i = 0; i < list.size(); i++) {
            MonthSupplytaskDtl monthSupplytaskDtlVo1 = new MonthSupplytaskDtl();
            monthSupplytaskDtlVo1.setId(list.get(i).getId());
            monthSupplytaskDtlVo1.setType(list.get(i).getType());
            monthSupplytaskDtlVo1.setContent(list.get(i).getContent());
            monthSupplytaskDtlVo1.setName(list.get(i).getName());
            monthSupplytaskDtlVo1.setScore(list.get(i).getScore());
            monthSupplytaskDtlVo1.setSelfValue(list.get(i).getSelfValue());

            MonthSupplytaskDtl monthSupplytaskDtlVo2 = new MonthSupplytaskDtl();
            monthSupplytaskDtlVo2.setFkTaskId(taskId);
            monthSupplytaskDtlVo2.setTab(tab);
            monthSupplytaskDtlVo2.setThreegradeNum(list.get(i).getId());
            List<MonthSupplytaskDtl> monthSupplytaskDtlVos = monthSupplytaskDtlService.list4subaudit(monthSupplytaskDtlVo2);

            //查询是否有辅助说明文档
            for (MonthSupplytaskDtl supplytaskDtl : monthSupplytaskDtlVos) {
                //临时增加，去除换行符，否则前端传递参数带换行符有问题，后期考虑前端优化
                String content = supplytaskDtl.getContent();
                Pattern p = Pattern.compile("\\s*|\t|\r|\n"); // 去除多个空格，去除制表符，回车，换行
                Matcher m = p.matcher(content);
                content = m.replaceAll("");
                supplytaskDtl.setContent(content);
                //查询是否有辅助说明文档
                InfoTargetStepExample infoTargetStepExample = new InfoTargetStepExample();
                infoTargetStepExample.createCriteria().andFkTargetIdEqualTo(supplytaskDtl.getNum());
                List<InfoTargetStep> infoTargetSteps = infoTargetStepService.selectByExample(infoTargetStepExample);
                if (infoTargetSteps!=null && infoTargetSteps.size()>0){
                    supplytaskDtl.setIshasStep(MonthConstant.IS);
                }else {
                    supplytaskDtl.setIshasStep(MonthConstant.NOT);
                }

            }

            //查询三级项目对应模块下的自评价总分
            BigDecimal pro4Score = BigDecimal.ZERO;
            BigDecimal pro4subScore = BigDecimal.ZERO;
            MonthSupplytaskDtlExample monthSupplytaskDtlExample = new MonthSupplytaskDtlExample();
            MonthSupplytaskDtlExample.Criteria criteria = monthSupplytaskDtlExample.createCriteria();
            criteria.andFkTaskIdEqualTo(taskId);
            criteria.andFkParentProjectIdEqualTo(list.get(i).getId());
            List<MonthSupplytaskDtl> monthSupplytaskDtls = monthSupplytaskDtlService.selectByExample(monthSupplytaskDtlExample);
            //查询对应四级下的五级自评价分数不为空的List
            List<MonthSupplytaskDtl> collect = monthSupplytaskDtls.stream().filter(s -> Strings.isNotBlank(s.getSelfScore())).collect(Collectors.toList());
            if (collect.size() == monthSupplytaskDtls.size()) {
                pro4Score = monthSupplytaskDtls.stream().map(MonthSupplytaskDtl::getSelfScore).map(BigDecimal::new).reduce(BigDecimal.ZERO, BigDecimal::add);
            }

            monthSupplytaskDtlVo1.setProscore(pro4Score.toString());


            //计算分公司审核分总分
            List<MonthSupplytaskDtl> iscollect = monthSupplytaskDtls.stream().filter(s -> MonthConstant.IS.equals(s.getIsSubauditedit())).collect(Collectors.toList());
            List<MonthSupplytaskDtl> notcollect = monthSupplytaskDtls.stream().filter(s -> MonthConstant.NOT.equals(s.getIsSubauditedit())).collect(Collectors.toList());
            BigDecimal isAuditScore = iscollect.stream().map(MonthSupplytaskDtl::getSubreviewScore).map(BigDecimal::new).reduce(BigDecimal.ZERO, BigDecimal::add);
            BigDecimal notAuditScore = notcollect.stream().map(MonthSupplytaskDtl::getSelfScore).map(BigDecimal::new).reduce(BigDecimal.ZERO, BigDecimal::add);
            pro4subScore = isAuditScore.add(notAuditScore);
            monthSupplytaskDtlVo1.setSubscore(pro4subScore.toString());
            resultList.add(monthSupplytaskDtlVo1);
            resultList.addAll(monthSupplytaskDtlVos);

        }
        map.put("code", 0);
        map.put("msg", "");
        map.put("count", resultList.size());
        map.put("data", resultList);
        return map;
    }

    /**
     * 更新月度填报项目及四级项目分数计算
     *
     * @param
     * @param
     * @return
     */
    @ApiOperation(value = "更新月度必备项目自评价结果", notes = "更新月度必备项目自评价结果")
    @PostMapping("/updateSelf")
    @ResponseBody
    public AjaxResult updateSelf(@RequestBody MonthSupplytaskDtl monthSupplytaskDtl) {
        MonthSupplytaskDtl monthSupplytaskDtl4 = monthSupplytaskDtlService.updateSelf(monthSupplytaskDtl);
        return toAjax(monthSupplytaskDtlService.updateByPrimaryKeySelective(monthSupplytaskDtl4));
    }


    /**
     * 审核页面查询对应标签下的对应审核内容
     *
     * @param
     * @param
     * @return
     */
    @ApiOperation(value = "查询五级填报项目及其上级", notes = "查询五级填报项目及其上级")
    @GetMapping("/list4audit/{taskId}/{tab}")
    @ResponseBody
    public Map<String, Object> list4audit(@PathVariable("taskId") String taskId, @PathVariable("tab") String tab, MonthSupplytaskDtl monthSupplytaskDtlVo) {
        Map<String, Object> map = new HashMap<>();
        List<MonthSupplytaskDtl> resultList = new ArrayList<>();

        MonthSupplytaskDtl monthSupplytaskDtl = new MonthSupplytaskDtl();
        monthSupplytaskDtl.setTab(tab);
        monthSupplytaskDtl.setDeptId(ShiroUtils.getDepId());
        monthSupplytaskDtl.setFkTaskId(taskId);

        //查询三级固定项目
        List<InfoProjectVo> list = infoProjectService.findupGrade3Dep(monthSupplytaskDtl);
        for (int i = 0; i < list.size(); i++) {
            MonthSupplytaskDtl monthSupplytaskDtlVo1 = new MonthSupplytaskDtl();
            monthSupplytaskDtlVo1.setId(list.get(i).getId());
            monthSupplytaskDtlVo1.setType(list.get(i).getType());
            monthSupplytaskDtlVo1.setContent(list.get(i).getContent());
            monthSupplytaskDtlVo1.setName(list.get(i).getName());
            monthSupplytaskDtlVo1.setScore(list.get(i).getScore());
            monthSupplytaskDtlVo1.setSelfValue(list.get(i).getSelfValue());

            MonthSupplytaskDtl monthSupplytaskDtlVo2 = new MonthSupplytaskDtl();
            monthSupplytaskDtlVo2.setFkTaskId(taskId);
            monthSupplytaskDtlVo2.setTab(tab);
            monthSupplytaskDtlVo2.setThreegradeNum(list.get(i).getId());
            monthSupplytaskDtlVo2.setDeptId(ShiroUtils.getDepId());
            List<MonthSupplytaskDtl> monthSupplytaskDtlVos = monthSupplytaskDtlService.findAuditTabbyThree(monthSupplytaskDtlVo2);

            //查询是否有辅助说明文档
            for (MonthSupplytaskDtl supplytaskDtl : monthSupplytaskDtlVos) {
                //临时增加，去除换行符，否则前端传递参数带换行符有问题，后期考虑前端优化
                String content = supplytaskDtl.getContent();
                Pattern p = Pattern.compile("\\s*|\t|\r|\n"); // 去除多个空格，去除制表符，回车，换行
                Matcher m = p.matcher(content);
                content = m.replaceAll("");
                supplytaskDtl.setContent(content);
                //查询是否有辅助说明文档
                InfoTargetStepExample infoTargetStepExample = new InfoTargetStepExample();
                infoTargetStepExample.createCriteria().andFkTargetIdEqualTo(supplytaskDtl.getNum());
                List<InfoTargetStep> infoTargetSteps = infoTargetStepService.selectByExample(infoTargetStepExample);
                if (infoTargetSteps!=null && infoTargetSteps.size()>0){
                    supplytaskDtl.setIshasStep(MonthConstant.IS);
                }else {
                    supplytaskDtl.setIshasStep(MonthConstant.NOT);
                }

            }

            //查询三级项目对应模块下的自评价总分
            BigDecimal pro4Score = BigDecimal.ZERO;
            BigDecimal pro4AuditScore = BigDecimal.ZERO;
            MonthSupplytaskDtlExample monthSupplytaskDtlExample = new MonthSupplytaskDtlExample();
            MonthSupplytaskDtlExample.Criteria criteria = monthSupplytaskDtlExample.createCriteria();
            criteria.andFkTaskIdEqualTo(taskId);
            criteria.andFkParentProjectIdEqualTo(list.get(i).getId());
            List<MonthSupplytaskDtl> monthSupplytaskDtls = monthSupplytaskDtlService.selectByExample(monthSupplytaskDtlExample);
            //计算自评分总分
            List<MonthSupplytaskDtl> collect = monthSupplytaskDtls.stream().filter(s -> Strings.isNotBlank(s.getSelfScore())).collect(Collectors.toList());
            if (collect.size() == monthSupplytaskDtls.size()) {
                pro4Score = monthSupplytaskDtls.stream().map(MonthSupplytaskDtl::getSelfScore).map(BigDecimal::new).reduce(BigDecimal.ZERO, BigDecimal::add);
            }
            monthSupplytaskDtlVo1.setProscore(pro4Score.toString());
            //计算审核分总分
            List<MonthSupplytaskDtl> iscollect = monthSupplytaskDtls.stream().filter(s -> MonthConstant.IS.equals(s.getIsAuditedit())).collect(Collectors.toList());
            List<MonthSupplytaskDtl> notcollect = monthSupplytaskDtls.stream().filter(s -> MonthConstant.NOT.equals(s.getIsAuditedit())).collect(Collectors.toList());
            BigDecimal isAuditScore = iscollect.stream().map(MonthSupplytaskDtl::getReviewScore).map(BigDecimal::new).reduce(BigDecimal.ZERO, BigDecimal::add);
            BigDecimal notAuditScore = notcollect.stream().map(MonthSupplytaskDtl::getSelfScore).map(BigDecimal::new).reduce(BigDecimal.ZERO, BigDecimal::add);
            pro4AuditScore = isAuditScore.add(notAuditScore);
            monthSupplytaskDtlVo1.setAuditScore(pro4AuditScore.toString());
            resultList.add(monthSupplytaskDtlVo1);
            resultList.addAll(monthSupplytaskDtlVos);
        }
        map.put("code", 0);
        map.put("msg", "");
        map.put("count", resultList.size());
        map.put("data", resultList);
        return map;
    }

    /**
     * 查询五级填报项目及其上级溯源
     *
     * @param
     * @param
     * @return
     */
    @ApiOperation(value = "查询五级填报项目及其上级", notes = "查询五级填报项目及其上级")
    @GetMapping("/list4SelfResult/{taskId}/{tab}")
    @ResponseBody
    public Map<String, Object> list4SelfResult(@PathVariable("taskId") String taskId, @PathVariable("tab") String tab, MonthSupplytaskDtl monthSupplytaskDtlVo) {
        Map<String, Object> map = new HashMap<>();
        List<MonthSupplytaskDtl> resultList = new ArrayList<>();

        InfoProjectVo infoProjectVo = new InfoProjectVo();
        infoProjectVo.setTab(tab);
        //查询三级固定项目
        List<InfoProjectVo> list = infoProjectService.findupGrade3(infoProjectVo);
        for (int i = 0; i < list.size(); i++) {
            MonthSupplytaskDtl monthSupplytaskDtlVo1 = new MonthSupplytaskDtl();
            monthSupplytaskDtlVo1.setId(list.get(i).getId());
            monthSupplytaskDtlVo1.setType(list.get(i).getType());
            monthSupplytaskDtlVo1.setContent(list.get(i).getContent());
            monthSupplytaskDtlVo1.setName(list.get(i).getName());
            monthSupplytaskDtlVo1.setScore(list.get(i).getScore());
            monthSupplytaskDtlVo1.setSelfValue(list.get(i).getSelfValue());

            MonthSupplytaskDtl monthSupplytaskDtlVo2 = new MonthSupplytaskDtl();
            monthSupplytaskDtlVo2.setFkTaskId(taskId);
            monthSupplytaskDtlVo2.setTab(tab);
            monthSupplytaskDtlVo2.setThreegradeNum(list.get(i).getId());
            List<MonthSupplytaskDtl> monthSupplytaskDtlVos = monthSupplytaskDtlService.list4SelfResult(monthSupplytaskDtlVo2);

            //查询是否有辅助说明文档
            for (MonthSupplytaskDtl supplytaskDtl : monthSupplytaskDtlVos) {
                //临时增加，去除换行符，否则前端传递参数带换行符有问题，后期考虑前端优化
                String content = supplytaskDtl.getContent();
                Pattern p = Pattern.compile("\\s*|\t|\r|\n"); // 去除多个空格，去除制表符，回车，换行
                Matcher m = p.matcher(content);
                content = m.replaceAll("");
                supplytaskDtl.setContent(content);
                //查询是否有辅助说明文档
                InfoTargetStepExample infoTargetStepExample = new InfoTargetStepExample();
                infoTargetStepExample.createCriteria().andFkTargetIdEqualTo(supplytaskDtl.getNum());
                List<InfoTargetStep> infoTargetSteps = infoTargetStepService.selectByExample(infoTargetStepExample);
                if (infoTargetSteps!=null && infoTargetSteps.size()>0){
                    supplytaskDtl.setIshasStep(MonthConstant.IS);
                }else {
                    supplytaskDtl.setIshasStep(MonthConstant.NOT);
                }

            }

            //查询三级项目对应模块下的自评价总分
            BigDecimal pro4Score = BigDecimal.ZERO;
            BigDecimal pro4AuditScore = BigDecimal.ZERO;
            MonthSupplytaskDtlExample monthSupplytaskDtlExample = new MonthSupplytaskDtlExample();
            MonthSupplytaskDtlExample.Criteria criteria = monthSupplytaskDtlExample.createCriteria();
            criteria.andFkTaskIdEqualTo(taskId);
            criteria.andFkParentProjectIdEqualTo(list.get(i).getId());
            List<MonthSupplytaskDtl> monthSupplytaskDtls = monthSupplytaskDtlService.selectByExample(monthSupplytaskDtlExample);
            List<MonthSupplytaskDtl> collect = monthSupplytaskDtls.stream().filter(s -> Strings.isNotBlank(s.getSelfScore())).collect(Collectors.toList());
            if (collect.size() == monthSupplytaskDtls.size()) {
                pro4Score = monthSupplytaskDtls.stream().map(MonthSupplytaskDtl::getSelfScore).map(BigDecimal::new).reduce(BigDecimal.ZERO, BigDecimal::add);
            }
            monthSupplytaskDtlVo1.setProscore(pro4Score.toString());

            //查询三级项目对应模块下的审核分总分
            List<MonthSupplytaskDtl> iscollect = monthSupplytaskDtls.stream().filter(s -> MonthConstant.IS.equals(s.getIsAuditedit())).collect(Collectors.toList());
            List<MonthSupplytaskDtl> notcollect = monthSupplytaskDtls.stream().filter(s -> MonthConstant.NOT.equals(s.getIsAuditedit())).collect(Collectors.toList());
            BigDecimal isAuditScore = iscollect.stream().map(MonthSupplytaskDtl::getReviewScore).map(BigDecimal::new).reduce(BigDecimal.ZERO, BigDecimal::add);
            BigDecimal notAuditScore = notcollect.stream().map(MonthSupplytaskDtl::getSelfScore).map(BigDecimal::new).reduce(BigDecimal.ZERO, BigDecimal::add);
            pro4AuditScore = isAuditScore.add(notAuditScore);
            monthSupplytaskDtlVo1.setAuditScore(pro4AuditScore.toString());

            resultList.add(monthSupplytaskDtlVo1);
            resultList.addAll(monthSupplytaskDtlVos);
        }
        map.put("code", 0);
        map.put("msg", "");
        map.put("count", resultList.size());
        map.put("data", resultList);
        return map;
    }

}
